package fr.inserm.umr915.vcfannotator.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.InputStreamSource;
import org.springframework.core.io.UrlResource;

public class IOUtils
	{
	public static InputStreamSource createFileInputSource(String uri) throws IOException
		{
		InputStreamSource in=null;
		if(uri.startsWith("http://") || uri.startsWith("ftp://") || uri.startsWith("https://"))
			{
			in=new UrlResource(uri);
			}
		else
			{
			in=new FileSystemResource(uri);
			}
		if(uri.toLowerCase().endsWith(".gz")) in=new GZipInputStreamSource(in);
		return in;
		}
	
	public static InputStream openStream(String uri) throws IOException
		{
		return createFileInputSource(uri).getInputStream();
		}
	
	public static BufferedReader openReader(String uri) throws IOException
		{
		return new BufferedReader(new InputStreamReader(openStream(uri)));
		}
	}
